package o;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Environment;
import android.os.storage.StorageManager;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.UUID;

public class dfw {
    public static String ˋ(Context context) {
        return ˋ(context, "/feedback/image/");
    }

    public static String ˎ(Context context) {
        return ˋ(context, "/feedback/logIn/");
    }

    public static String ˏ(Context context) {
        return ˋ(context, "/feedback/logOut/");
    }

    public static String ॱ(Context context) {
        return ˋ(context, "/feedback/files/");
    }

    public static String ˊ(Context context) {
        return ˋ(context, "/feedback/");
    }

    public static String ˋ(Context context, String str) {
        return doc.ॱ(context) + str;
    }

    private static String ॱ(String str) {
        if (str == null || !str.contains("/sdcard")) {
            return str;
        }
        return str.substring("/sdcard".length());
    }

    public static String ˎ(String str) {
        if (doc.ˋ()) {
            return ˋ() + ॱ(str);
        }
        return str;
    }

    public static String ˊ(Context context, String str) {
        return ॱ(context, true) + ॱ(str);
    }

    public static LinkedList<File> ˊ(String str) {
        if (dof.ॱ(str)) {
            return null;
        }
        LinkedList<File> linkedList = new LinkedList();
        File file = new File(str);
        if (!(file.exists() || file.mkdir())) {
            Logger.e("UploadFileUtils", "listLinkedFiles makedir failed");
        }
        File[] listFiles = file.listFiles();
        if (listFiles != null) {
            for (Object add : listFiles) {
                linkedList.add(add);
            }
        }
        return linkedList;
    }

    public static void ॱ(File file) {
        if (file.isDirectory()) {
            File[] listFiles = file.listFiles();
            if (listFiles != null) {
                for (File ॱ : listFiles) {
                    ॱ(ॱ);
                }
            }
            if (!file.delete()) {
                Logger.e("UploadFileUtils", "deleteFile delete Files failed");
            }
        } else if (file.exists() && !file.delete()) {
            Logger.e("UploadFileUtils", "deleteFile delete File failed");
        }
    }

    private static void ˋ(String str) {
        try {
            File file = new File(str);
            if (!file.exists() && !file.mkdirs()) {
                Logger.e("UploadFileUtils", "makeRootDirectory mkdirs failed");
            }
        } catch (Throwable th) {
            Logger.e("UploadFileUtils", "makeRootDirectory Exception");
        }
    }

    public static File ʽ(Context context) {
        String format = new SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()));
        String uuid = UUID.randomUUID().toString();
        String str = format + "_" + uuid.substring(uuid.length() - 10) + ".zip";
        ˋ(ˋ(context, "/feedback/files/"));
        try {
            return new File(ˋ(context, "/feedback/files/") + str);
        } catch (Throwable th) {
            Logger.e("UploadFileUtils", "getAllFileZipPath Exception");
            return null;
        }
    }

    public static File ˏ(String str) {
        String format = new SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()));
        String uuid = UUID.randomUUID().toString();
        String str2 = format + "_" + uuid.substring(uuid.length() - 10) + ".zip";
        ˋ(str);
        try {
            return new File(str + str2);
        } catch (Exception e) {
            Logger.e("UploadFileUtils", "getLogFilePath Exception");
            return null;
        }
    }

    public static void ॱ(Context context, String str) {
        Closeable fileOutputStream;
        Throwable th;
        int i = 1;
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(str, options);
        float f = (float) options.outWidth;
        float f2 = (float) options.outHeight;
        if (f2 <= f) {
            f2 = f;
        }
        int i2 = (int) (f2 / 800.0f);
        if (i2 > 1) {
            i = i2;
        }
        options.inSampleSize = i;
        options.inJustDecodeBounds = false;
        Bitmap decodeFile = BitmapFactory.decodeFile(str, options);
        File file = new File(ˋ(context, "/feedback/image/"));
        if (!(file.exists() || file.mkdirs())) {
            Logger.e("UploadFileUtils", "saveBitmapToSD mkdir fail");
        }
        File file2 = new File(ˋ(context, "/feedback/image/"), System.currentTimeMillis() + ".jpg");
        Closeable closeable = null;
        try {
            fileOutputStream = new FileOutputStream(file2);
            try {
                decodeFile.compress(CompressFormat.JPEG, 100, fileOutputStream);
                if (!decodeFile.isRecycled()) {
                    decodeFile.recycle();
                }
                dnw.ˎ(fileOutputStream);
            } catch (FileNotFoundException e) {
                try {
                    Logger.e("UploadFileUtils", "FileNotFoundException Exception");
                    dnw.ˎ(fileOutputStream);
                } catch (Throwable th2) {
                    Throwable th3 = th2;
                    closeable = fileOutputStream;
                    th = th3;
                    dnw.ˎ(closeable);
                    throw th;
                }
            }
        } catch (FileNotFoundException e2) {
            fileOutputStream = null;
            Logger.e("UploadFileUtils", "FileNotFoundException Exception");
            dnw.ˎ(fileOutputStream);
        } catch (Throwable th4) {
            th = th4;
            dnw.ˎ(closeable);
            throw th;
        }
    }

    private static String ॱ(Context context, boolean z) {
        StorageManager storageManager = (StorageManager) context.getSystemService("storage");
        try {
            Class cls = Class.forName("android.os.storage.StorageVolume");
            Method method = storageManager.getClass().getMethod("getVolumeList", new Class[0]);
            Method method2 = cls.getMethod("getPath", new Class[0]);
            Method method3 = cls.getMethod("isRemovable", new Class[0]);
            Object invoke = method.invoke(storageManager, new Object[0]);
            int length = Array.getLength(invoke);
            for (int i = 0; i < length; i++) {
                Object obj = Array.get(invoke, i);
                String str = (String) method2.invoke(obj, new Object[0]);
                if (z == ((Boolean) method3.invoke(obj, new Object[0])).booleanValue()) {
                    return str;
                }
            }
        } catch (ClassNotFoundException e) {
            Logger.e("UploadFileUtils", "ClassNotFoundException Exception");
        } catch (InvocationTargetException e2) {
            Logger.e("UploadFileUtils", "InvocationTargetException Exception");
        } catch (NoSuchMethodException e3) {
            Logger.e("UploadFileUtils", "NoSuchMethodException Exception");
        } catch (IllegalAccessException e4) {
            Logger.e("UploadFileUtils", "IllegalAccessException Exception");
        }
        return null;
    }

    private static String ˋ() {
        return Environment.getExternalStorageDirectory().getPath();
    }
}
